﻿@model List<WebEntities.Models.WebInfo.AdvItem>

@{
    ViewBag.Title = "网站管理平台_广告管理视图";
}

@section HeadContent
{
    <script src="/Scripts/AdvItem/index.js" type="text/javascript"></script>
}

@(Html.X().Menu()
    .ID("Grid1CtxMenu")
    .Items(
        Html.X().MenuItem().Text("编辑广告").Icon(Icon.BookEdit)
            .DirectEvents(de =>
            {
                de.Click.Action = "EditAdvItemWindow";
                de.Click.ExtraParams.Add(new Parameter("advId", "this.parentMenu.dataRecord.data.AdvID", ParameterMode.Raw));
            }),
        Html.X().MenuItem().Text("删除广告").Icon(Icon.Cross).Listeners(ls => ls.Click.Handler = "App.BtnDeleteSel.getEl().dom.click()")
    )
)

@Html.X().Hidden().ID("DeleteHint").Text("是否要删除选中的广告条目？")

@(Html.X().Viewport()
    .Layout(LayoutType.Border)
    .Items(
        Html.X().Panel()
            .Region(Region.West)
            .Width(200)
            .Title("广告栏目列表")
            .Collapsible(true)
            .Split(true)
            .MinWidth(150)
            .MaxWidth(300)
            .Layout(LayoutType.Fit)
            .Items(
                Html.X().GridPanel().ID("AdvSuiteGrid")
                    .Store(
                        Html.X().Store()
                            .AutoSync(true)
                            .ShowWarningOnFailure(false)
                            .Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
                                .Url(Url.Action("GetAllAdvSuite", "AdvSuite"))
                                .ExtraParams(ep => ep.Add(new Parameter("withAllOption", "true", ParameterMode.Raw)))
                                .Reader(Html.X().JsonReader().Root("data").IDProperty("SuiteID"))
                                .Writer(writer => new JsonWriter { AllowSingle = true, Root = "data" })
                                .API(api =>
                                {
                                    api.Destroy = Url.Action("DeleteAdvSuite", "AdvSuite");
                                    api.Update = Url.Action("UpdateAdvSuite", "AdvSuite");
                                })
                            ))
                            .Model(Html.X().Model().IDProperty("SuiteID")
                                .Fields(
                                    new ModelField("SuiteID", ModelFieldType.Int),
                                    new ModelField("SuiteName")
                                )
                            )
                    )
                    .ColumnModel(
                        Html.X().Column().DataIndex("SuiteID").Text("ID"),
                        Html.X().Column().DataIndex("SuiteName").Text("栏目名称").Flex(1).MenuDisabled(true).Editor(Html.X().TextField())
                     )
                    .SelectionModel(Html.X().RowSelectionModel().Mode(SelectionMode.Multi))
                    .Plugins(
                        Html.X().CellEditing().Listeners(ls =>
                        {
                            ls.BeforeEdit.Fn = "beforeEditSuite";
                        })
                    )
                    .Listeners(ls =>
                    {
                        ls.ItemClick.Fn = "changeSuite";
                    })
                    .View(Html.X().GridView().StripeRows(true))
                    .TopBar(
                        Html.X().Toolbar()
                            .Items(
                                Html.X().Button().Text("新建栏目").Icon(Icon.Add).DirectClickAction("NewAdvSuiteWindow", "AdvSuite"),
                                Html.X().Button().ID("BtnDeleteSuite").Text("删除栏目").Icon(Icon.Cross)
                                    .Listeners(
                                        ls => ls.Click.Fn = "deleteSuiteGridSelected"
                                    )
                            )
                    )
            ),
        Html.X().Panel()
            .Region(Region.Center)
            .Title("广告列表")
            .Layout(LayoutType.Fit)
            .Items(
                Html.X().GridPanel()
                    .ID("GridPanel1")
                    .Store(
                        Html.X().StoreForModel()
                            .AutoSync(true)
                            .PageSize(50)
                            .ShowWarningOnFailure(false)
                            .Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
                                .Url(Url.Action("GetAllAdvItemByPage"))
                                .ExtraParams(ep =>
                                {
                                    ep.Add(new Parameter("suiteId", "0"));
                                })
                                .Reader(Html.X().JsonReader().Root("data"))
                                .Writer(writer => new JsonWriter { AllowSingle = true, Root = "data" })
                                .API(api => { api.Destroy = Url.Action("DeleteAdvItem"); })
                            ))
                            .Listeners(ls => ls.Write.Fn = "ext.net.comjs.onGridChange")
                    )
                    .ColumnModel(
                        Html.X().RowNumbererColumn(),
                        Html.X().Column().DataIndex(Model, m => m.AdvID).Text("广告ID"),
                        Html.X().Column().DataIndex(Model, m => m.AdvTitle).Text("广告标题"),
                        Html.X().Column().DataIndex(Model, m => m.AdvType).Text("广告类别").Renderer("renderAdvType"),
                        Html.X().Column().DataIndex(Model, m => m.AppearRate).Text("出现频率"),
                        Html.X().Column().DataIndex(Model, m => m.SuiteName).Text("所属栏目"),
                        Html.X().Column().DataIndex(Model, m => m.PicLink).Text("广告外链"),
                        Html.X().Column().DataIndex(Model, m => m.AdvWidth).Text("广告宽度"),
                        Html.X().Column().DataIndex(Model, m => m.AdvHeight).Text("广告高度"),
                        Html.X().DateColumn().DataIndex(Model, m => m.BTime).Text("开始日期").Format("yyyy-MM-dd").Width(100),
                        Html.X().DateColumn().DataIndex(Model, m => m.ETime).Text("结束日期").Format("yyyy-MM-dd").Width(100),
                        Html.X().DateColumn().DataIndex(Model, m => m.CreateTime).Text("创建时间").Format("yyyy-MM-dd HH:mm:ss").Width(120),
                        Html.X().Column().DataIndex(Model, m => m.Creator).Text("创建者"),
                        Html.X().DateColumn().DataIndex(Model, m => m.CreateTime).Text("更新时间").Format("yyyy-MM-dd HH:mm:ss").Width(120),
                        Html.X().Column().DataIndex(Model, m => m.Modifier).Text("更新者")
                     )
                    .SelectionModel(Html.X().CheckboxSelectionModel().Mode(SelectionMode.Multi))
                    .Listeners(ls =>
                    {
                        ls.ItemContextMenu.Handler = "e.preventDefault(); App.Grid1CtxMenu.dataRecord = this.store.getAt(index); App.Grid1CtxMenu.showAt(e.getXY());";
                    })
                    .View(Html.X().GridView().StripeRows(true))
                    .DirectEvents(de =>
                    {
                        de.ItemDblClick.Action = "EditAdvItemWindow";
                        de.ItemDblClick.ExtraParams.Add(new Parameter("advId", "record.data['AdvID']", ParameterMode.Raw));
                    })
                    .TopBar(
                        Html.X().Toolbar()
                            .Items(
                                Html.X().Button().Text("新建广告").Icon(Icon.Add).DirectClickAction("NewAdvItemWindow"),
                                Html.X().Button().ID("BtnDeleteSel").Text("删除广告").Icon(Icon.Cross)
                                    .Listeners(
                                        ls => ls.Click.Fn = "ext.net.comjs.deleteGridSelected"
                                    )
                            )
                    )
                    .BottomBar(
                        Html.X().PagingToolbar()
                            .Items(
                                Html.X().Label("每页显示行数："),
                                Html.X().ToolbarSpacer(10),
                                Html.X().ComboBox()
                                    .Width(80)
                                    .Items("10", "50", "100")
                                    .SelectedItems("50")
                                    .Listeners(lr =>
                                    {
                                        lr.Select.Fn = "ext.net.comjs.onPageSizeChange";
                                    })
                            )
                    )
            )
    )
)